/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.discount.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.discount.entity.DiscountBrandType;
import com.jeesite.modules.discount.service.DiscountBrandTypeService;

/**
 * 品牌类型Controller
 * @author czp
 * @version 2018-07-08
 */
@Controller
@RequestMapping(value = "${adminPath}/discount/discountBrandType")
public class DiscountBrandTypeController extends BaseController {

	@Autowired
	private DiscountBrandTypeService discountBrandTypeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DiscountBrandType get(String id, boolean isNewRecord) {
		return discountBrandTypeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("discount:discountBrandType:view")
	@RequestMapping(value = {"list", ""})
	public String list(DiscountBrandType discountBrandType, Model model) {
		model.addAttribute("discountBrandType", discountBrandType);
		return "modules/discount/discountBrandTypeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("discount:discountBrandType:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DiscountBrandType> listData(DiscountBrandType discountBrandType, HttpServletRequest request, HttpServletResponse response) {
		Page<DiscountBrandType> page = discountBrandTypeService.findPage(new Page<DiscountBrandType>(request, response), discountBrandType); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("discount:discountBrandType:view")
	@RequestMapping(value = "form")
	public String form(DiscountBrandType discountBrandType, Model model) {
		model.addAttribute("discountBrandType", discountBrandType);
		return "modules/discount/discountBrandTypeForm";
	}

	/**
	 * 保存品牌类型
	 */
	@RequiresPermissions("discount:discountBrandType:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DiscountBrandType discountBrandType) {
		discountBrandTypeService.save(discountBrandType);
		return renderResult(Global.TRUE, "保存品牌类型成功！");
	}
	
	/**
	 * 停用品牌类型
	 */
	@RequiresPermissions("discount:discountBrandType:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DiscountBrandType discountBrandType) {
		discountBrandType.setStatus(DiscountBrandType.STATUS_DISABLE);
		discountBrandTypeService.updateStatus(discountBrandType);
		return renderResult(Global.TRUE, "停用品牌类型成功");
	}
	
	/**
	 * 启用品牌类型
	 */
	@RequiresPermissions("discount:discountBrandType:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DiscountBrandType discountBrandType) {
		discountBrandType.setStatus(DiscountBrandType.STATUS_NORMAL);
		discountBrandTypeService.updateStatus(discountBrandType);
		return renderResult(Global.TRUE, "启用品牌类型成功");
	}
	
	/**
	 * 删除品牌类型
	 */
	@RequiresPermissions("discount:discountBrandType:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DiscountBrandType discountBrandType) {
		discountBrandTypeService.delete(discountBrandType);
		return renderResult(Global.TRUE, "删除品牌类型成功！");
	}
	
}